package net.shopxx.entity;

import java.math.BigDecimal;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import net.shopxx.util.SystemConfigUtil;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 实体类 - 订单
 */

@Entity
@Table(name = "airOrder")
public class AirOrder extends BaseEntity {

	private static final long serialVersionUID = -8541323033439515148L;

	public static final int DEFAULT_ORDER_LIST_PAGE_SIZE = 15;// 订单列表默认每页显示数

	// 订单状态（未处理、已处理、已完成、已评论、关闭、已作废）
	public enum OrderStatus  {
		unprocessed, processed, completed,commented,closed,invalid
	};

	// 付款状态（未支付、部分支付、已支付、部分退款、全额退款）
	public enum PaymentStatus {
		unpaid, partPayment, paid, partRefund, refunded
	};

	// 配送状态（未发货、部分发货、已发货、确认收货、部分退货、已退货）
	public enum ShippingStatus {
		unshipped, partShipped, shipped,confirmed, partReshiped, reshiped
	};

	private String orderSn;// 订单编号
	private OrderStatus orderStatus;// 订单状态
	private PaymentStatus paymentStatus;// 支付状态
	private String deliveryTypeName;// 配送方式名称
	private String paymentConfigName;// 支付方式名称
	private BigDecimal productTotalPrice;// 商品总价格
	private BigDecimal deliveryFee;// 配送费用
	private BigDecimal paymentFee;// 支付费用
	private BigDecimal totalAmount;// 订单总额
	private String memo;// 附言

	private Set<Passenger> passengerSet;
	private Set<Flight> flightSet;
	private Set<Price> priceSet;
	private OrderInfo orderInfo;
	private LinkerInfo linkerInfo;
	
	
	private Member member;// 会员
	
	@Column(unique = true, updatable = false, nullable = false)
	public String getOrderSn() {
		return orderSn;
	}
	
	public void setOrderSn(String orderSn) {
		this.orderSn = orderSn;
	}
	
	@Enumerated
	@Column(nullable = false)
	public OrderStatus getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(OrderStatus orderStatus) {
		this.orderStatus = orderStatus;
	}

	@Enumerated
	@Column(nullable = false)
	public PaymentStatus getPaymentStatus() {
		return paymentStatus;
	}

	public void setPaymentStatus(PaymentStatus paymentStatus) {
		this.paymentStatus = paymentStatus;
	}

	@Column(precision = 15, scale = 5, nullable = false)
	public BigDecimal getProductTotalPrice() {
		return productTotalPrice;
	}
	
	// 精度处理
	public void setProductTotalPrice(BigDecimal productTotalPrice) {
		this.productTotalPrice = SystemConfigUtil.getOrderScaleBigDecimal(productTotalPrice);
	}
	
	@Column(precision = 15, scale = 5, nullable = true)
	public BigDecimal getDeliveryFee() {
		return deliveryFee;
	}
	
	// 精度处理
	public void setDeliveryFee(BigDecimal deliveryFee) {
		this.deliveryFee = SystemConfigUtil.getOrderScaleBigDecimal(deliveryFee);
	}
	
	@Column(precision = 15, scale = 5, nullable = false)
	public BigDecimal getPaymentFee() {
		return paymentFee;
	}

	// 精度处理
	public void setPaymentFee(BigDecimal paymentFee) {
		this.paymentFee = SystemConfigUtil.getOrderScaleBigDecimal(paymentFee);
	}

	@Column(precision = 15, scale = 5, nullable = false)
	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	// 精度处理
	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = SystemConfigUtil.getOrderScaleBigDecimal(totalAmount);
	}
	
	@Column(nullable = true)
	public String getDeliveryTypeName() {
		return deliveryTypeName;
	}
	
	public void setDeliveryTypeName(String deliveryTypeName) {
		this.deliveryTypeName = deliveryTypeName;
	}
	
	@Column(nullable = true)
	public String getPaymentConfigName() {
		return paymentConfigName;
	}

	public void setPaymentConfigName(String paymentConfigName) {
		this.paymentConfigName = paymentConfigName;
	}
	
	@Column(length = 5000)
	public String getMemo() {
		return memo;
	}
	
	public void setMemo(String memo) {
		this.memo = memo;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}
	

	@OneToMany(mappedBy = "airOrder", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.PERSIST})
	@OrderBy("createDate desc")
	public Set<Passenger> getPassengerSet() {
		return passengerSet;
	}

	public void setPassengerSet(Set<Passenger> passengerSet) {
		this.passengerSet = passengerSet;
	}

	@OneToMany(mappedBy = "airOrder", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.PERSIST})
	@OrderBy("createDate desc")
	public Set<Price> getPriceSet() {
		return priceSet;
	}

	public void setPriceSet(Set<Price> priceSet) {
		this.priceSet = priceSet;
	}


	@OneToOne(fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.PERSIST})
	public OrderInfo getOrderInfo() {
		return orderInfo;
	}

	public void setOrderInfo(OrderInfo orderInfo) {
		this.orderInfo = orderInfo;
	}
	
	@OneToOne(fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.PERSIST})
	@OrderBy("createDate desc")
	public LinkerInfo getLinkerInfo() {
		return linkerInfo;
	}

	public void setLinkerInfo(LinkerInfo linkerInfo) {
		this.linkerInfo = linkerInfo;
	}


	@OneToMany(mappedBy = "airOrder", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.PERSIST})
	@OrderBy("createDate desc")
	public Set<Flight> getFlightSet() {
		return flightSet;
	}

	public void setFlightSet(Set<Flight> flightSet) {
		this.flightSet = flightSet;
	}
	
	

}